<?
	session_start();
?>
<link rel="stylesheet" type="text/css" href="../style/style.css">
<body>
<script language="javascript">
function exit(Str)
{
		var NIKa = document.forms[Str].NIK.value;
		var Namaa = document.forms[Str].Nama.value;
		if (!opener.closed)
		{
			opener.document.forms[0].nik.value = NIKa;
			opener.document.forms[0].nama.value = Namaa;
			close();
		}
}

function on_top()
{
	if (child != null)
		if (child.closed)
			child = null;
		else
			child.focus();
			else
			{
			
			}
}
</script>
<?
// cek session
if($_SESSION['user_login'] == ""){
	echo"
	<br><br><br><br><br><br>
		<div align='center' style='color: red;'>
		 Maaf, Anda tidak bisa mengakses halaman ini ... <br><br>
		 [ <a href=\"../index.php\"' target='_blank'>silahkan login disini</a> ]
		</div>
	";
	exit();
}

include("../lib/config.php");
include("../lib/function.php");
include("../lib/header.php");
//include("header.php");
	//$op		= $HTTP_GET_VARS['op'];
	$keyword= $HTTP_GET_VARS['keyword'];
	//$cat	= $HTTP_GET_VARS['show'];
	$show	= $HTTP_GET_VARS['show'];
	$page 	= $HTTP_GET_VARS['page']; // get nomor halaman yang dipanggil
	$next	= $HTTP_GET_VARS['next']; // get segmen halaman yang dipanggil

if($show == "cari"){
	$sql_a = "SELECT count(*) FROM Karyawan WHERE (Nama LIKE '%$keyword%') OR (NIK LIKE '%$keyword%') ";
}
elseif($show == ""){
	$sql_a = "SELECT count(*) FROM Karyawan";
}

	$result	= mssql_query($sql_a,$conn);
	$total	= mssql_fetch_row($result);
	$limit	= 10;
	$pager  = Pager::getPagerData($total[0], $limit, $page);
	$offset = $pager->offset;
	$limit  = $pager->limit;
	$page   = $pager->page;

if($show == "cari"){
	$sql	= "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS 'RowNumber', NIK, Nama FROM Karyawan WHERE (Nama LIKE '%$keyword%') OR (NIK LIKE '%$keyword%') ) SELECT * FROM limit WHERE RowNumber BETWEEN ".$offset." AND ".($offset+$limit).""; 
}
elseif($show == ""){
	$sql	= "WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS 'RowNumber', NIK, Nama FROM Karyawan) SELECT * FROM limit WHERE RowNumber BETWEEN ".$offset." AND ".($offset+$limit).""; 
}
	
$query		=mssql_query($sql,$conn);
$jml		=mssql_num_rows($query);
//echo"$jml";

	echo"<b>Daftar Karyawan</b>";
	echo"
	<table width=100% cellpadding=0 cellspacing=0>
	<form name=search method=get action=".$PHP_SELF.">
	 <tr>
	  <td><input type='text' name='keyword'><input type='hidden' name='show' value='cari' > <input class='button' type=submit value=Cari></td>
	 </tr>	</form>
	</table>
	";
	Paging1($pager,$page,$next,$limit,$keyword,$show);
	echo"<table cellpadding=1 cellspacing=1 width=100%>";
	echo"
	 <tr class=headlist>
	  <td><b>NIK</b></td>
	  <td><b>Nama</b></td>
	  <td>&nbsp;</td>
	 </tr>
	";
if($jml > 0)
{
	
	for($i=0;$i<$jml;$i++)
	{
		$row=mssql_fetch_array($query);
		echo"<form name='form$i'><tr>";
		echo"<tr class=contentlist>";		
		echo"
			<td>".$row[NIK]."</td>
			<td>".$row[Nama]."</td>
			<td>
			 <input type='hidden' name='NIK' value='".$row[NIK]."'>
			 <input type='hidden' value='".$row[Nama]."' name='Nama' readonly>
			 <input type='button' value='&radic; pilih' class='button' onclick=\"Javascript:exit('form$i'); return false;\">
			</td>
			</tr>
			</form>
			";
	}
}
	echo"</td></tr></table>";
	echo"</tr></table>";
	echo"</div>";

	/*
	echo"Daftar Karyawan";
	Paging($pager,$page,$next,$limit,$keyword,$show);
	
	echo"<table cellpadding=2 width=100%>";
	echo"
	 <tr>
	  <td><b>No</b></td>
	  <td><b>NIK</b></td>
	  <td><b>Nama</b></td>
	  <td>&nbsp;</td>
	 </tr>
	";
	//ShowDataList($conn,$sql,$cat);
	
	echo"</table>";*/
	echo"<br>
	<div align=center><input type=button value=Tutup class='button' onclick=Javascript:self.close()></div>";
//}
?>